<?php
/**
 * Created by ThinkPHP5.0.22.
 * User: 小涛.
 * Date: 2018/12/27.
 * Time: 0:04.
 */

namespace app\admin\model;


use think\Model;
use think\Request;

/**
 * Class GoodsType 商品分类
 * @package app\admin\model
 */
class GoodsType extends Model
{
    //商品分类图片与图片的对应关系
    public function UploadLogo()
    {
        return $this->belongsTo("Upload", "logo", "id");
    }

    //商品分类与父类的对应关系
    public function GoodsType()
    {
        return $this->belongsTo("GoodsType", "type_id", "id");
    }

    //商品分类中父类与子类的对应关系
    public function TypeId()
    {
        return $this->hasMany("GoodsType", "type_id", "id")
            ->with("GoodsType,UploadLogo")
            ->order("sort asc");
    }


    //列表
    public static function listGoodsType($type_id = 0,$row = 4){
        return self::with("TypeId,GoodsType,UploadLogo") -> where(["type_id" => $type_id])
            -> order("sort asc") -> paginate($row,false,[
                "query" => Request::instance() -> param()
            ]);
    }

    //查询
    public static function selectGoodsType($type_id = 0){
        return self::with("TypeId,GoodsType,UploadLogo")
            -> where(["type_id" => $type_id])
            -> order("sort asc")
            -> select();
    }


}
